﻿@using DNA.Mvc;
@using DNA.Mvc.Community;
@using System;
@using System.Web.Mvc;
@using System.Web.Mvc.Ajax;
@using DNA.Mvc.jQuery;
@using DNA.Mvc.Community.Controllers;

@helper GetForumIconHtml(ForumWrapper forum)
    {
        string _class = "forum-icon forum-icon-forum";

        if (forum.IsLocked || forum.IsModerated)
        {
            _class += " forum-icon-forum-locked";
        }
        else
        {
            if (forum.HasChildren)
            {
                _class += " forum-icon-forum-subforum";
            }
            else
            {
                _class += " forum-icon-forum-read";
            }
        }
    <div class="@_class">
    </div>
}
@helper GetThreadIconHtml(Thread thread)
    {
        TagBuilder tag = new TagBuilder("div");
        if (thread.IsLocked)
        {
            if (thread.IsPinned)
            {
                tag.AddCssClass("forum-icon-thread forum-icon-thread-announce");
            }
            else
            {
                tag.AddCssClass("forum-icon-thread forum-icon-thread-lock");
            }
        }
        else
        {
            if (thread.IsPinned)
            {
                tag.AddCssClass("forum-icon-thread forum-icon-thread-pinned");
            }
            else
            {
                TimeSpan timeSpan = DateTime.Now - thread.LastPosted;
                if (thread.TotalReads >= 100)
                {
                    tag.AddCssClass("forum-icon-thread forum-icon-thread-hot");
                }
                else
                {
                    if ((timeSpan.Days == 0) || (timeSpan.Days <= 1))
                    {
                        tag.AddCssClass("forum-icon-thread forum-icon-thread-new");
                    }
                    else
                    {
                        tag.AddCssClass("forum-icon-thread forum-icon-thread-default");
                    }
                }
            }
        }
    @MvcHtmlString.Create(tag.ToString());
}
@helper AttachmentLink(Attachment attachment, object htmlAttributes)
    {
        string path = "/webshared/home/forums/attachments/" + attachment.PostID.ToString() + "/" + attachment.FileName;
        TagBuilder builder = new TagBuilder("a");
        if (htmlAttributes != null)
        {
            builder.MergeAttributes<string, object>(ObjectHelper.ConvertObjectToDictionary(htmlAttributes));
        }
        builder.InnerHtml = attachment.FileName;
        builder.Attributes.Add("href", path);
        builder.Attributes.Add("target", "_blank");
    @MvcHtmlString.Create(builder.ToString());
}
